package com.example.componenttest

//加上open关键字  表明A类可以被继承
open class A( val name: String,val age: Int) {

    fun eat(){
        println(name+" is eat. He is "+age+" years old.")
    }

}

class B(val sno: String,val grade: Double,name: String,age: Int): A(name,age){
    init {
        println("sno is "+sno)
        print("grade is "+grade)
    }

    constructor(sno: String, grade: Double):this(sno,grade,"",0)
    constructor():this("", 0.0)
}

data class CDataClass(val brand:String,val price:Double)

fun main(){
//    var b = B("201671084",4.5,"zy",23)
//    b.eat()

    val cellPhone1 = CDataClass("Samsung",123.0)
    val cellPhone2 = CDataClass("Samsung",123.0)
    println(cellPhone1)
    println(cellPhone1==cellPhone2)
    Singleton.singletonTest()
    val list = listOf<String>("A","B")
    val list1= mutableListOf<String>("A","B")
    list1.add("C")
    for (fruit in list1)
        println(fruit)
    val fruit = list1.maxByOrNull { it.length }
    println(fruit)

    val list2=list1.map { it.toLowerCase() }
    println(list2)

//    Thread(object :Runnable{
//        override fun run() {
//            TODO("Not yet implemented")
//        }
//    }).start()

    var thread=Thread { println("the thread is running~~~") }
    thread.start()
    thread.join()

    printParams(1)
    printParams1(str="zy")
}

fun printParams(num: Int,str: String = "hello"){
    println("num is $num, str is $str")
}

fun printParams1(num: Int = 100,str: String ){
    println("num is $num, str is $str")
}

object Singleton{
    fun singletonTest()= println("singletonTest is called")
}